﻿using System;
using System.IO;
using MalRec.Base.Service;
using Microsoft.Practices.ServiceLocation;

namespace MalRec.Base.ExceptionHandling
{
    public class ExceptionConfiguration
    {
        #region public members

        private string _TraceFileName;

        /// <summary>
        /// Gets the trace filename
        /// </summary>
        public string TraceFileName
        {
            get
            {
                string ret = _TraceFileName;
                if (ret == null) ret = "";
                if (!ret.Contains(":"))
                {
                    try
                    {
                        ret = Path.Combine(ApplicationService.UserConfigurationPath, ret);
                    }
                    catch (Exception) { }
                }
                return ret;
            }
            private set
            {
                _TraceFileName = value;
            }
        }

        /// <summary>
        /// Gets or sets the trace db connectionstring
        /// </summary>
        public string TraceDbConnectionString
        {
            get;
            set;
        }

        /// <summary>
        /// Gets info if the default connectionstring should be used
        /// </summary>
        public bool UseDefaultConnectionString
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the trace db tablename
        /// </summary>
        public string TraceDbTableName
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the configured error dialog type
        /// </summary>
        public string DialogType
        {
            get;
            private set;
        }

        #endregion public members

        #region constructors

        /// <summary>
        /// creates and initializes a new <see cref="ExceptionConfiguration"/> object
        /// </summary>
        /// <param name="traceFileName">the trace filename</param>
        /// <param name="traceDbConnectionString">the trace db connection string</param>
        /// <param name="traceDbTableName">the trace db table name</param>
        /// <param name="useDefaultConnectionString">the used default connection string</param>
        /// <param name="dialogType">the dialog type</param>
        public ExceptionConfiguration(string traceFileName, string traceDbConnectionString, string traceDbTableName, bool useDefaultConnectionString, string dialogType)
        {
            TraceFileName = traceFileName;
            TraceDbConnectionString = traceDbConnectionString;
            TraceDbTableName = traceDbTableName;
            UseDefaultConnectionString = useDefaultConnectionString;
            DialogType = dialogType;
        }

        #endregion constructors
    }
}